<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>我的投递</title>
    <link rel="shortcut icon" href="../../image/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../../css/main.css" media="all">
    <link rel="stylesheet" href="../../css/ok/oksub.css">
    <script type="text/javascript" src="../../libs/loading/okLoading.js"></script>
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-container">
        <div class="ok-body">
            <!--数据表格-->
            <table id="stuPostion" lay-filter="studentPostion"></table>
        </div>
    </div>
</div>
<script src="../../libs/layui/layui.js"></script>
<script>
    layui.use(["element", "table", "form", "laydate", "okLayer", "okUtils",], function () {
        let table = layui.table;
        let form = layui.form;
        let laydate = layui.laydate;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;

        okLoading.close();

        laydate.render({elem: "#startTime", type: "datetime"});
        laydate.render({elem: "#endTime", type: "datetime"});

        // 获取contentText
        const ctx = function () {
            let pathName = document.location.pathname;
            let index = pathName.substr(1).indexOf("/");
            let result = pathName.substr(0, index + 1);
            return result;
        }();

        // 获取student
        var student = JSON.parse(window.sessionStorage.getItem("student"));


        //数据渲染
        var stuposttable = table.render({
            elem: '#stuPostion'
            , url: ctx + '/ygssecs/getdeliveryRecord' //数据接口
            , where: {stuid: student.stuid}
            , loading: true
            , page: {
                limit: 10
                , layout: ['prev', 'page', 'next', 'count', 'skip']
            }
            , response: {
                statusName: 'code' //规定数据状态的字段名称，默认：code
                , statusCode: 200 //规定成功的状态码，默认：0
                , msgName: 'msg' //规定状态信息的字段名称，默认：msg
                , countName: 'count' //规定数据总数的字段名称，默认：count
                , dataName: 'data' //规定数据列表的字段名称，默认：data
            }, request: {
                pageName: 'pageNum'
                , limitName: 'pageSize'
            }
            , cols: [[ //表头
                {title: '序号', type: 'numbers', width: 50, sort: false, align: 'center', fixed: 'left'}
                , {
                    field: 'recordid', title: '应聘记录id', unresize: true, hide: true
                }, {
                    field: 'jobid', title: '岗位ID', unresize: true, hide: true, templet: function (d) {
                        return d.job ? d.job.jobid || '' : ''
                    }
                }, {
                    field: 'enterpriseid', title: '企业ID', unresize: true, hide: true, templet: function (d) {
                        return d.job.enterprise ? d.job.enterprise.enterpriseid || '' : ''
                    }
                }
                , {
                    field: 'jobname',
                    title: '岗位名称',
                    fixed: 'left',
                    unresize: true,
                    width: 130,
                    align: 'center',
                    templet: function (d) {
                        return d.job ? d.job.jobname || '' : ''
                    }
                }
                , {
                    field: 'educationrequirements', title: '学历要求', unresize: true, width: 110, templet: function (d) {
                        return d.job ? d.job.educationrequirements || '' : ''
                    }
                }
                , {
                    field: 'needpeople',
                    title: '需求人数',
                    unresize: true,
                    width: 90,
                    align: 'center',
                    templet: '<div>{{ d.job.needpeople }} 人</div>'
                }
                , {
                    field: 'workingexperience',
                    title: '工作经验',
                    unresize: true,
                    width: 90,
                    align: 'center',
                    templet: function (d) {
                        return d.job ? d.job.workingexperience || '' : ''
                    }
                }
                , {
                    field: 'workplace',
                    title: '工作地点',
                    unresize: true,
                    align: 'center',
                    width: 100,
                    templet: function (d) {
                        return d.job ? d.job.workplace || '' : ''
                    }
                }
                , {
                    field: 'jobsalary', title: '薪资', unresize: true, width: 80, align: 'center', templet: function (d) {
                        return d.job ? d.job.jobsalary || '' : ''
                    }
                }, {
                    field: 'descriptionofjob', title: '职位描述', unresize: true, width: 278, templet: function (d) {
                        return d.job ? d.job.descriptionofjob || '' : ''
                    }
                }
                , {
                    field: 'jobrequirement',
                    title: '留言',
                    unresize: true,
                    width: 80,
                    align: 'center',
                    templet: '#lookover'
                }
                , {title: '操作', unresize: true, width: 100, align: 'center', fixed: 'right', templet: '#operationTpl'}
            ]]
        });

        //表格行内事件
        table.on("tool(studentPostion)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "viewDetails":
                    viewDetails(data.job.jobid);
                    console.log("jobid", data.job.jobid)
                    break;
                case "viewCompany":
                    viewCompany(data.job.enterprise.enterpriseid);
                    break;
                case "look":
                    layer.open({
                        type: 2,
                        title: '消息',
                        shadeClose: true,
                        shade: 0.4,
                        area: ['900px', '600px'],
                        content: 'studentChatPage.html?recordid=' + data.recordid + "&priseid=" + data.job.enterprise.enterpriseid
                    });
                    break;
            }
        });

        //查看详情
        function viewDetails(jobid) {
            okLayer.open("查看岗位信息", "jobDetail-stu.html", "90%", "90%", function (layero) {
                let iframeWin = window[layero.find("iframe")[0]["name"]];
                iframeWin.initForm(jobid);
            }, function () {
                stuposttable.reload();
            })
        }

        //查看公司
        function viewCompany(enterpriseid) {
            okLayer.open("查看公司信息", "enterpriseDetails.html", "90%", "90%", function (layero) {
                let iframeWin = window[layero.find("iframe")[0]["name"]];
                iframeWin.initpriseid(enterpriseid);
            })
        }
    });
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
    <a href="javascript:" title="查看详情" lay-event="viewDetails"><i class="layui-icon">&#xe609;</i></a>
    <a href="javascript:" title="查看公司" lay-event="viewCompany" style="margin-left: 15px;"><i
            class="layui-icon">&#xe60b;</i></a>
</script>
<script type="text/html" id="lookover">
    <a href="javascript:" class="layui-btn layui-btn-normal layui-btn-xs"
       lay-event="look">查看</a>
</script>
</body>
</html>